home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- ($op = shift) || die "Usage: ren perlexpr [filenames]\n";
-
- # First, get the list of filenames. Use @ARGV if specified.
- # Otherwise, do all files in the current directory if STDIN is
- # a tty, otherwise read the filenames from STDIN.
-
- if (!@ARGV)
- {
- if (-t)
- {
- @ARGV = ('*');
- }
- else
- {
- @ARGV = <STDIN>;
- chop(@ARGV);
- }
- }
-
- # Now, expand wildcards in the argument list...
-
- foreach (@ARGV)
- {
- push(@a,<${_}>);
- }
-
- @ARGV = @a;
-
- # Now, rename each file in turn
-
- for (@ARGV) {
- $was = $_;
- eval $op;
- die $@ if $@;
- rename($was,$_) unless $was eq $_;
- }
-
- # Some useful subroutines...
-
- sub cap {
- tr/A-Z/a-z/;
- substr($_,$[,1) =~ tr/a-z/A-Z/;
- }
-